home *** CD-ROM | disk | FTP | other *** search
Wrap
# Source Generated with Decompyle++ # File: in.pyc (Python 2.4) '''A TransactionManager controls transaction boundaries. It coordinates application code and resource managers, so that they are associated with the right transaction. ''' import thread from transaction._transaction import Transaction _marker = object() def _new_transaction(txn, synchs): if synchs: synchs.map((lambda s: s.newTransaction(txn))) class TransactionManager(object): def __init__(self): WeakSet = WeakSet import ZODB.utils self._txn = None self._synchs = WeakSet() def begin(self): if self._txn is not None: self._txn.abort() txn = self._txn = Transaction(self._synchs, self) _new_transaction(txn, self._synchs) return txn def get(self): if self._txn is None: self._txn = Transaction(self._synchs, self) return self._txn def free(self, txn): if not txn is self._txn: raise AssertionError self._txn = None def registerSynch(self, synch): self._synchs.add(synch) def unregisterSynch(self, synch): self._synchs.remove(synch) def commit(self, sub = _marker): if sub is _marker: sub = None else: deprecated37 = deprecated37 import ZODB.utils deprecated37('subtransactions are deprecated; use transaction.savepoint() instead of transaction.commit(1)') return self.get().commit(sub, deprecation_wng = False) def abort(self, sub = _marker): if sub is _marker: sub = None else: deprecated37 = deprecated37 import ZODB.utils deprecated37('subtransactions are deprecated; use sp.rollback() instead of transaction.abort(1), where `sp` is the corresponding savepoint captured earlier') return self.get().abort(sub, deprecation_wng = False) def savepoint(self, optimistic = False): return self.get().savepoint(optimistic) class ThreadTransactionManager(TransactionManager): '''Thread-aware transaction manager. Each thread is associated with a unique transaction. ''' def __init__(self): self._txns = { } self._synchs = { } def begin(self): tid = thread.get_ident() txn = self._txns.get(tid) if txn is not None: txn.abort() synchs = self._synchs.get(tid) if synchs is None: WeakSet = WeakSet import ZODB.utils synchs = self._synchs[tid] = WeakSet() txn = self._txns[tid] = Transaction(synchs, self) _new_transaction(txn, synchs) return txn def get(self): tid = thread.get_ident() txn = self._txns.get(tid) if txn is None: synchs = self._synchs.get(tid) if synchs is None: WeakSet = WeakSet import ZODB.utils synchs = self._synchs[tid] = WeakSet() txn = self._txns[tid] = Transaction(synchs, self) return txn def free(self, txn): tid = thread.get_ident() if not txn is self._txns.get(tid): raise AssertionError del self._txns[tid] def registerSynch(self, synch): tid = thread.get_ident() ws = self._synchs.get(tid) if ws is None: WeakSet = WeakSet import ZODB.utils ws = self._synchs[tid] = WeakSet() ws.add(synch) def unregisterSynch(self, synch): tid = thread.get_ident() ws = self._synchs[tid] ws.remove(synch)